<?php

namespace app\controller;

use app\service\DemandOrderService;
use support\Request;
use support\Response;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

class DemandOrderController
{
    private DemandOrderService $demandOrderService;

    public function __construct()
    {
        $this->demandOrderService = DemandOrderService::getInstance();
    }

    /**
     * 需求变更列表统计
     * @param Request $request
     * @return Response
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function changeCount(Request $request): Response
    {
        $param = $request->post();
        $res = $this->demandOrderService->changeCount($param);
        return json(success_response('success', $res));
    }


    /**
     * 需求按阶段下发数据统计统计
     * @param Request $request
     * @return Response
     */
    public function countByStage(Request $request): Response
    {
        $param = $request->post()['param'];
        $res = $this->demandOrderService->countByStage($param['project_id'], $param['episode_code'], $param['group_type']);
        return json(success_response('success', $res));
    }
}
